<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:src="@{/js/ions_alert.js}"></script>
    <script th:src="@{/common/common.js}"></script>
    <script th:src="@{/js/sweetalert.min.js}"></script>
    <link rel="stylesheet" th:href="@{/css/sweetalert.css}">
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <xblock>
        <button class="layui-btn" id="add_sales"><i
                class="layui-icon"></i>注册
        </button>
    </xblock>
    <table class="layui-table middle">
        <thead>
        <tr>
            <th width="6%">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>售货员用户名</th>
            <th>售货员密码</th>
            <th>售货员姓名</th>
            <th>售货员等级</th>
            <th>注册时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tbody" class="salesList">
        <tr th:each="sales:${SALES_LIST}">
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td id="username" th:text="${sales.getUsername()}"></td>
            <td id="password" th:text="${sales.password}"></td>
            <td id="name" th:text="${sales.getName()}"></td>
            <td id="number" th:text="${sales.getPower()}">{.Pid}}</td>
            <td id="time" th:text=" ${#dates.format(sales.getCreateTime(), 'yyyy-MM-dd HH:mm:ss ')}">{{date .CreateTime "Y-m-d H:m:s"}}</td>
            <td class="td-manage">
                <a style="cursor: pointer" class="layui-btn layui-btn-mini layui-btn-danger delete_btn" th:onclick="deleteConfirm([[${sales.getUsername()}]])">
                    <i class="layui-icon" >&#x1006;</i>禁用
                </a>
            </td>
        </tr>
        </tbody>
    </table>

</div>
<script>


    $(function () {
        $("#add_sales").click(function () {

            $.ajax({
                url:"/admin/sales/addSales",
                type:"PUT",
                success:function (resultInfo) {
                    if (resultInfo.flag) {
                        location.reload();
                    }else {
                        alert("添加失败！");
                    }
                }
            })
        });

    });
    function deleteConfirm(no) {
        let b = confirm("确认禁用吗？");
        if(b){
            $.ajax({
                url: "/admin/sales/deleteSales",
                data:{
                    username: no,
                },
                type: "DELETE",
                success:function (resultInfo) {
                    alert(resultInfo.message);
                    if(resultInfo.flag){
                        window.location.reload();
                    }
                }
            })
        }
    }
</script>
</body>
</html>